home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / MacShell / ! MacShell.fn.descriptions next >
Encoding:
Text File  |  1991-12-04  |  35.6 KB  |  691 lines  |  [TEXT/MPS ]

  1. /************** AEConnect.c **************/
  2.  
  3. void            InitConnectAppleEvents(void);
  4. /* This function initializes the connect AppleEvents stuff.  It needs to be
  5. ** called so that MacShell applications can connect with other applications
  6. ** specific to a targeted window. */
  7.  
  8. pascal OSErr    DoAEAnswer(AppleEvent *message, AppleEvent *reply, long refcon);
  9. /* This function handles the connect reply.  MacShell sends the connect request
  10. ** via kAEQueueReply.  This means that it doesn't necessarily come back immediately.
  11. ** (It actually comes back right away if it is connected to itself.)  The reply
  12. ** normally comes in via a high-level event.  Until this reply comes in, the
  13. ** connection isn't established.  When this reply does come in, the remaining
  14. ** information necessary to establish the connection to a particular window in
  15. ** the target application is recorded. */
  16.  
  17. OSErr            SendConnect(FileRecHndl frHndl);
  18. /* This is the function that is called to establish a connection to another MacShell-based
  19. ** application.  The "other" MacShell application is probably the same application on
  20. ** another machine.  This code does a bit more than simply connecting to another
  21. ** application.  It targets a specific window within that application.  It doesn't just
  22. ** target zone/machine/application, which is the granularity that AppleEvents gives you.
  23. ** It also passes back and forth some information that is kind of a pain to get, but
  24. ** is nice to have.  One such piece of information is the user name.  This needs to be
  25. ** sent.  It can't be determined from the message from an AppleEvent.  The sender sends
  26. ** the user name, and the receiver returns the remote user name.  The user name is
  27. ** placed in the document record for the window to be used if you wish. */
  28.  
  29. pascal OSErr    ReceiveConnect(AppleEvent *message, AppleEvent *reply, long refcon);
  30. /* This function receives a connect message from SendConnect.  The connection
  31. ** tasks that the receiver has to do are done here, such as opening a window for
  32. ** this end of the connection, etc.  It also returns whether or not it succeeded,
  33. ** and the user name.  Basically, it establishes the connection, while keeping
  34. ** some data as to whom it is connected to. */
  35.  
  36. pascal OSErr    ReceiveConnectReply(AppleEvent *message, AppleEvent *reply);
  37. /* This function is called when you want to determine which window an AppleEvent
  38. ** is targeted for.  MacShell AppleEvents send two long values along with the AppleEvent
  39. ** to determine which window is the target window.  One of the longs is an ID for the
  40. ** sender, and the other is an ID for the receiver.  When a connection is established,
  41. ** these values are saved for both the sender and the receiver.  This allows the
  42. ** AppleEvent to be sent in either direction and still be targeted to the correct window.
  43. ** To find which window is the target, get these two longs out of the AppleEvent and then
  44. ** call GetAEWindow.  The first value is always the ID of the machine itself, and the
  45. ** second value is always the ID of the remote machine.  Due to this, you will need to
  46. ** reverse the order of these ID's for incomming MacShell AppleEvents. */
  47.  
  48. WindowPtr        GetAEWindow(long windID_0, long windID_1);
  49. /* This function is called to determine which window, if any, is the designated
  50. ** target window.  The window ID's are determined when the connection is established. */
  51.  
  52. pascal Boolean    AEPortFilter(LocationNamePtr locationName, PortInfoPtr thePortInfo);
  53. /* This function doesn't allow the PPCBrowser to display any applications other
  54. ** than the designated application(s). */
  55.  
  56.  
  57.  
  58. /************** AECustom.c **************/
  59.  
  60. void            InitCustomAppleEvents(void);
  61. /* This function initializes the custom AppleEvents stuff.  Any custom AppleEvents
  62. ** you create should be added to the AppleEvents dispatch table here. */
  63.  
  64. OSErr            SendMessage(FileRecHndl frHndl, short messageType);
  65. /* A lot of times the data that you want to send is just a hunk of data.  You really
  66. ** aren't all that concerned about any particular format.  If you are both the sender
  67. ** and receiver, then you know what is going on, and sometimes this is just fine.
  68. ** Of course, this means that you won't be communicating this data with other
  69. ** applications in any meaningful sort of way.  If this private quick-and-dirty data
  70. ** sending is what you want, then SendMessage will do it for you.
  71. ** In Kibitz, I had two kinds of data that were less than 32k.  I had sound data, and
  72. ** I had TextEdit text.  Both of these data types were just a bunch of bytes.
  73. ** SendMessage allows you to assign a data type, and then the block of data.
  74. ** It is a convenient way to send smaller, private blocks of data.  The data will be
  75. ** received by the function ReceiveMessage. */
  76.  
  77. pascal OSErr    ReceiveMessage(AppleEvent *message, AppleEvent *reply, long refcon);
  78. /* This function is where you get the data sent by SendMessage.  The kind of data
  79. ** is determined by an assigned message type.  Based on this value, you will
  80. ** interpret the data in varying ways, depending on the needs of your application. */
  81.  
  82.  
  83.  
  84. /************** AERequired.c **************/
  85.  
  86. void            InitRequiredAppleEvents(void);
  87. /* Intializes AppleEvent dispatcher table for the required events.  It also
  88. ** determines if the machine is PPCBrowser and AppleEvent capable.  If so,
  89. ** the booleans gHasAppleEvents and gHasPPCToolbox are set true.  This function
  90. ** must be the first AppleEvents initialization MacShell function called, as the
  91. ** other functions depend on the booleans being set correctly. */
  92.  
  93. pascal OSErr    DoAEOpenApplication(AppleEvent *message, AppleEvent *reply, long refcon);
  94. /* This function opens a new MacShell document due to an AppleEvents request. */
  95.  
  96. pascal OSErr    DoAEOpenDocuments(AppleEvent *message, AppleEvent *reply, long refcon);
  97. /* This function opens existing MacShell documents due to an AppleEvents request. */
  98.  
  99. pascal OSErr    DoAEPrintDocuments(AppleEvent *message, AppleEvent *reply, long refcon);
  100. /* This function prints MacShell documents due to an AppleEvents request. */
  101.  
  102. pascal OSErr    DoAEQuitApplication(AppleEvent *message, AppleEvent *reply, long refcon);
  103. /* This function sets a quit flag so that MacShell will quit due to an AppleEvents request. */
  104.  
  105. OSErr            OpenDocEventHandler(AppleEvent *message, AppleEvent *reply, short mode);
  106. /* This is the function that actually does the document opening for AppleEvents. */
  107.  
  108.  
  109.  
  110. /************** AEUtils.c **************/
  111.  
  112. void            DoHighLevelEvent(EventRecord *event);
  113. /* This function simply calls AEProcessAppleEvent and reports any errors. */
  114.  
  115. OSErr            GetTargetInfo(AEAddressDesc targetDesc, StringPtr zone, StringPtr machine, StringPtr application);
  116. /* This function returns the zone, machine, and application name for the
  117. ** indicated target descriptor. */
  118.  
  119. OSErr            MakeTarget(AEAddressDesc *target, Boolean sendDirect, short replyMode, Str255 prompt, Str255 applListLabel, PPCFilterProcPtr portFilter, char *theLocNBPType);
  120. /* Creates a TargetID.  If sendDirect is TRUE, the target is specified by setting
  121. ** a ProcessSerialNumber to kCurrentProcess.  This has the advantage of sending
  122. ** the message directly to ourselves, bypassing ePPC and gaining about a 10-15x
  123. ** speed improvement.  If sendDirect is FALSE, we see if we have the
  124. ** PPCToolBox.  If not, then we are forced to do a direct send.  If we do have
  125. ** the PPCToolbox, then we call PPCBrowser.  We then look at the reply, and
  126. ** factor in the mode we are going to use in AESend.  If that mode is
  127. ** kAEWaitReply and the user selected us as the target, we have to turn that
  128. ** into a direct send.  This is because the AppleEvent Manager will otherwise
  129. ** post the event as a high-level event.  However, we are busy waiting for a
  130. ** reply, not looking for events, so we'll hang.  We avoid this by forcing a
  131. ** direct send. */
  132.  
  133. Boolean            MissedAnyParameters(AppleEvent *message);
  134. /* Used to check for any unread required parameters. Returns true if we
  135. ** missed at least one. */
  136.  
  137.  
  138.  
  139. /************** AppleTalk.c **************/
  140.  
  141. OSErr            ATInit(void);
  142. /* Currently does nothing.  Calling it allows the AppleTalk.c.o file to be needed
  143. ** by the link. */
  144.  
  145. OSErr            DoBuildZoneList(ListHandle listHndl);
  146. /* Given a list record, this function places all of the zone names in
  147. ** the list.  Prior to calling this function, you need to create a
  148. ** list record that has zero rows and one column.  The zones are added
  149. ** to the list in the column in alphabetical order.  The function
  150. ** IUMagString is used to determine order. */
  151.  
  152. OSErr            DoSelectMyZone(ListHandle listHndl);
  153. /* Given a list of zones (probably generated by DoBuildZoneList), this
  154. ** function selects the zone the user is currently in.  The current zone
  155. ** is selected and scrolled into view. */
  156.  
  157. OSErr            AddPPCNBPAlias(NamesTableEntry *theNTE, Str32 newNBPType, EntityName *newEntity);
  158. /* This function regsters an alias for the application.  This allows PPCBrowser
  159. ** to be used to display only machines registered with that alias, instead of
  160. ** all machines that are PPCToolbox capable.  This function is called by 
  161. ** MacShell at startup time, as the alias only needs to be registered once.  If
  162. ** there is more than one version of the application running on a single
  163. ** machine, AddPPCNBPAlias will append a number to the application name.
  164. ** This allows each copy of the application to be displayed by PPCBrowser. */
  165.  
  166. OSErr            RemoveNBPAlias(EntityPtr theEntity);
  167. /* This function removes the designated alias.  This is executed by MacShell at
  168. ** application quit time. */
  169.  
  170.  
  171. /************** DoCursor.c **************/
  172.  
  173. void            DoCursor(void);
  174. /* The cursor management code for your application belongs here.  Your job is
  175. ** to update the cursor region and also to set the correct cursor for that
  176. ** region.  The region gCurrentCursorRgn will be used for the WaitNextEvent call.
  177. ** This global region should be updated by DoCursor. */
  178.  
  179. void            DoSetCursor(Cursor *cursor);
  180. /* DoCursor is normally used to set the cursor.  DoCursor also sets the cursor
  181. ** region for the WaitNextEvent call.  DoSetCursor is for when you need a temporary
  182. ** cursor for a dialog or alert, or whatever.  You can call DoSetCursor to set this
  183. ** temporary cursor.  By calling DoSetCursor, you make sure that when you return to
  184. ** the main event loop, the cursor will be recalculated, even if it is still over
  185. ** the old cursor region.  You don't have to call DoSetCursor to cause the cursor
  186. ** and cursor region for WaitNextEvent to be recalculated.  You could also simply
  187. ** set gCursorPtr to nil. */
  188.  
  189.  
  190.  
  191. /************** DoEvent.c **************/
  192.  
  193. void            DoEvent(EventRecord *event);
  194. /* You definitely want to modify this function.  This is the main dispatcher for
  195. ** the application event loop.  Change the code for the different cases as is
  196. ** appropriate for your application. */
  197.  
  198. void            DoActivate(WindowPtr window, Boolean becomingActive);
  199. /* This function activates or deactivates the window, as appropriate.  It changes
  200. ** the state of the window controls and grow icon.  If there is anything else
  201. ** that needs to be done for your application's windows during activation or
  202. ** deactivation, then it needs to be done here. */
  203.  
  204. void            DoUpdate(WindowPtr window);
  205. /* This function is called to update the window contents.  It does this in two
  206. ** stages.  It first updates the document scrollbars (if any) and growIcon (if
  207. ** there is one).  It then sets up for updating the rest of the window content.
  208. ** This setup consists of removing the document scrollbar and growIcon area
  209. ** from the visRgn.  The area is removed from the visRgn so that the clipRgn
  210. ** can be used by the application for clipping.
  211. ** To update the document scrollbar and growIcon area, the function
  212. ** DoDrawScrollGrow is called.  To update the remainder of the content area,
  213. ** the procedure pointed to by the window's document field imageProc is called. */
  214.  
  215. /************** EventLoop.c **************/
  216.  
  217. void            EventLoop(void);
  218. /* This is the main application event loop.  It simply calls WaitNextEvent
  219. ** and DoEvent until the user decides to quit. */
  220.  
  221.  
  222.  
  223. /************** File.c **************/
  224.  
  225. OSErr            AppDisposeDocument(FileRecHndl frHndl);
  226. /* This function is automatically called by MacShell at appropriate times.  It
  227. ** calls AppFreeDocument, which is application specific.  See AppFreeDocument
  228. ** for more information. */
  229.  
  230. OSErr            AppNewDocument(FileRecHndl *returnHndl, OSType sftype);
  231. /* This function is automatically called by MacShell at appropriate times.  It
  232. ** calls AppInitDocument, which is application specific.  See AppInitDocument
  233. ** for more information. */
  234.  
  235. OSErr            AppOpenDocument(FileRecHndl *result, FSSpecPtr fileToOpen, char permission);
  236. /* This function does the human-interface thing for opening a document.  It
  237. ** also calls AppNewDocument to initialize a document.  To actually read in
  238. ** the data, AppOpenDocument calls AppReadDocument, which is application
  239. ** specific.  See AppReadDocument for more information. */
  240.  
  241. OSErr            AppSaveDocument(FileRecHndl    frHndl, WindowPtr window, short saveMode);
  242. /* This function does the human-interface thing for saving a document.  To
  243. ** actually write out the data, AppSaveDocument calls AppWriteDocument, which
  244. ** is application specific.  See AppWriteDocument for more information. */
  245.  
  246. void            ConvertOldToNewSFReply(SFReply *oldReply, StandardFileReply *newReply);
  247. /* When running on a pre-7.0 system, SFGetFile or SFPutFile is called.  Then
  248. ** ConvertOldToNewSFReply is called to convert the reply record to the new
  249. ** format.  This allows the rest of the application to use only a single
  250. ** record format. */
  251.  
  252. OSErr            Create_OpenFile(FSSpec *file, short *refNum);
  253. ** Opens the file specified by the passed FSSpec, creating it if it doesn't
  254. ** already exist. Refturns the refnum of the open file to the application.
  255. ** File Manager errors are reported and returned. */
  256.  
  257. Boolean         DisplayGetFile(StandardFileReply *reply);
  258. /* Simple routine to display a list of files with our file type. */
  259.  
  260. Boolean         DisplayPutFile(StandardFileReply *reply);
  261. /* Displays the StandardFile PutFile dialog box. Fills out the passed reply
  262. ** record, and returns the sfGood field as a result. */
  263.  
  264. void            IncNewFileNum(Boolean flag);
  265. /* This function sets a boolean that indicates whether or not the new file
  266. ** number should be incremented.  New files are opened with a default title.
  267. ** The title states that the document is untitled, and gives it a number.
  268. ** Sometimes you will want to open a file and not use a new untitled number.
  269. ** This would be for reasons of printing, or for a temporary work file.
  270. ** In these cases, you would first call IncNewFileNum with false.  You would
  271. ** then do the operations on the temporary file.  Once these operations are
  272. ** complete, you would then call IncNewFileNum with true to reenable untitled
  273. ** title incrementing. */
  274.  
  275.  
  276.  
  277. /************** File2.c **************/
  278.  
  279. void            AppFreeDocument(FileRecHndl frHndl);
  280. /* This function is where you do the application specific document disposal
  281. ** things.  This function is called by AppDisposeDocument at appropriate
  282. ** times by MacShell. */
  283.  
  284. OSErr            AppInitDocument(FileRecHndl frHndl);
  285. /* This function is where you do the application specific document
  286. ** initialization things.  This function is automatically called at
  287. ** appropriate times by MacShell. */
  288.  
  289. OSErr            AppReadDocument(FileRecHndl frHndl);
  290. /* This function is where the document data is read in.  This function is
  291. ** automatically called at appropriate times by MacShell.  Your application
  292. ** may not necessarily read in all of the data.  Your file may be disk-based.
  293. ** It is completely up to you.  Of course, if your document is disk-based,
  294. ** other parts of your application will need to know this and read in the
  295. ** data as needed.  (You can now do this by using VM.  Just read the document
  296. ** in as if you have lots of memory.)  This function also reads in the
  297. ** print record and file version number.  MacShell depends on there being
  298. ** a print record read in from the file.  The reason that this is not
  299. ** automatically done for you at a higher level is that this would place
  300. ** a restriction on the file format.  You may have the print record stored
  301. ** elsewhere, or your file may not have one saved.  In either case, you do
  302. ** need to read or produce one for the rest of MacShell to be happy.  Given that
  303. ** there is no restriction on the file format, you can use existing file
  304. ** formats within MacShell.  This allows your application to read other file
  305. ** formats from other applications. */
  306.  
  307. OSErr            AppWriteDocument(FileRecHndl frHndl);
  308. /* This function is where the document data is written out.  This function is
  309. ** automatically called at appropriate times by MacShell.  Your application
  310. ** may not necessarily write all of the data.  (See AppReadDocument.) */
  311.  
  312. OSErr            AppDuplicateDocument(FileRecHndl oldFrHndl, FileRecHndl *newFrHndl);
  313. /* This function is use to duplicate a document.  Your application may not
  314. ** have this feature.  If not, then yank the associated menu item and code, and
  315. ** this function as well. */
  316.  
  317.  
  318.  
  319. /************** Help.c **************/
  320.  
  321. void            DynamicBalloonHelp(void);
  322. /* This function is used to do balloon help for the content of a window. */
  323.  
  324.  
  325.  
  326. /************** IdleTasks.c **************/
  327.  
  328. void            DoIdleTasks(EventRecord *event);
  329. /* If your application has an tasks that need to be done at idle time, this
  330. ** is the place to put them.  It is automatically called at appropriate times
  331. ** by MacShell. */
  332.  
  333. void            NotifyCancel(void);
  334. void            NotifyUser(void);
  335. /* These two functions are the routines used to use the Notification Manager.
  336. ** NotifyUser is called by MacShell when an AppleEvent comes in to MacShell and
  337. ** MacShell isn't the front application.  NotifyCancel is called by MacShell when
  338. ** the user brings it to the front. */
  339.  
  340.  
  341.  
  342. /************** Init.c **************/
  343.  
  344. void            Initialize(void);
  345. void            StartDocuments(void);
  346. /* These functions are startup code that shouldn't have to change. */
  347.  
  348.  
  349.  
  350. /************** Menu.c **************/
  351.  
  352. void            AdjustMenus(void);
  353. /* This function is where your application would make menu changes, such as
  354. ** enabling or disabling menu choices, adding or removing menu items, etc. */
  355.  
  356. void            EnableOrDisableItem(MenuHandle menu, short item, Boolean enable);
  357. /* This function simply calle EnableItem or DisableItem, depending on the
  358. ** boolean value passed it. */
  359.  
  360. void            DoMenuCommand(long menuResult);
  361. /* This function is where your application would respond to menu commands. */
  362.  
  363.  
  364.  
  365. /************** Print.c **************/
  366.  
  367. OSErr            AppPrintDocument(FileRecHndl frHndl, Boolean jobDlg, Boolean firstJob);
  368. OSErr            PresentStyleDialog(FileRecHndl frHndl);
  369. /* These two functions are the generic print support for MacShell.  You shouldn't
  370. ** have to make any changes to these functions.  AppPrintDocument calls the
  371. ** designated image procedure.  The default procedure is ImageDocument.  You can
  372. ** change it if you wish.  ImageDocument images the document to either the window
  373. ** or to the printer.  The port is already set when ImageDocument is called to either
  374. ** the window's port or the printer port.  The global variable gPrintPage is set
  375. ** so that you can determine if you are imaging for the window or for the printer.
  376. ** If gPrintPage is 0 then you are imaging for the window.  If gPrintPage is non-0,
  377. ** then that is the page you are imaging to the printer.  If you are printing, and
  378. ** have imaged the final page, your imaging code should set gPrintPage to 0.  This
  379. ** tells AppPrintDocument that you have done the final page.  The reason for this 
  380. ** is that the user could request to print pages 4 to 27, and you only have 14 pages
  381. ** in the document.  The imaging procedure "knows" how many pages the document
  382. ** has, and by having the imaging procedure return that it is finished, we eliminate
  383. ** the need for the generic print code to have to know how many pages are in the
  384. ** document. */
  385.  
  386.  
  387.  
  388. /************** Start.c **************/
  389.  
  390. void            main(void);
  391. /* This is where the MacShell application gets called first (obviously).
  392.  
  393.  
  394.  
  395. /************** Utils.c **************/
  396.  
  397. void            appendi2cstr(char *cstr, short i);
  398. short            appendi2pstr(char *pstr, short i);
  399. short            i2cstr(char *cstr, short i);
  400. void            i2pstr(char *pstr, short i);
  401. void            pstrcat(char *d, char *s);
  402. void            pstrcpy(char *d, char *s);
  403. short            GetHexByte(char *cptr);
  404. /* These functions are a collection of useful things for C programmers. */
  405.  
  406. pascal Boolean    alertFilter(DialogPtr dlg, EventRecord *event, short *item);
  407. /* The alert filter makes sure that that the outline for the button gets
  408. ** redrawn.  This is important if balloon help is on, as the balloon window
  409. ** can overlap the outline of the button and leave a portion of it erased. */
  410.  
  411. pascal Boolean    keyEquivFilter(DialogPtr dlg, EventRecord *event, short *item);
  412. /* The key equivalent filter allows you to assign key equivalents to dialog
  413. ** items.  Each item can have as many key equivalents as you wish.  You can
  414. ** also specify the exact state of the modifiers that you will or won't allow.
  415. ** The key equivalent information is stored in the resource fork, so the
  416. ** key equivalents can be easily localized.
  417. ** This code expects the key equivalents to be in item #2, which is a StatText
  418. ** item that is located so the text is outside of the dialog.  This allows us
  419. ** to put key equivalent information in the resource fork, so the key
  420. ** equivalents are localizable.
  421. **
  422. ** An example save changes before closing or quitting res source with
  423. ** keyEquiv info would look like:
  424. **
  425. ** resource 'DITL' (rYesNoCancel, purgeable) {
  426. **     {
  427. **         {71, 315, 91, 367}, Button     { enabled, "Save" },
  428. **         {0, -1000, 20, 2},  StaticText { disabled,
  429. **             "=S190001,=s190001,=D190003,=d190003,=.190104,1B190004" },
  430. **         {71, 80, 91, 162},  Button { enabled, "Don’t Save" },
  431. **         {71, 244, 91, 302}, Button { enabled, "Cancel" },
  432. **         {11, 78, 61, 366},  StaticText { disabled,
  433. **             "Save changes to the document “^0” before ^1?" },
  434. **         {11, 23, 43, 55},        Icon { disabled, 2 }
  435. **     }
  436. ** };
  437. **
  438. ** The document name would be the string for param #0.
  439. ** The text "closing" or "quitting" would be the string for param #1.
  440. **
  441. ** The keyEquiv entry is item #2, which has a rect that pushes it out of the
  442. ** dialog.  The string info is interpreted as to what the key/modifier combo
  443. ** is, and what dialog item it relates to.
  444. **
  445. ** A single key equiv entry is 8 characters.  Entries are separated by commas.
  446. **
  447. ** If the first character of an entry is an =, then the next character is the 
  448. ** key.  If the first character isn't an =, then the first two characters are 
  449. ** the hex value of the key.  (Ex:  =S or =s for save, 1B for ESC.)
  450. **
  451. ** If the key pressed is the same as the key value for any of the entries, then 
  452. ** the next two characters are the hex value for which modifiers to test.  This
  453. ** modifier test value is anded with the modifier.  The result is then compared 
  454. ** to the value of the next two hex digits.  If they are equal, then the 
  455. ** modifiers are correct, as well as the key.  If this is so, we have a winner.
  456. **
  457. ** "=S190001,=s190001,=D190003,=d190003,=.190104,1B190004"
  458. **
  459. ** The above string breaks down as follows:
  460. ** =S190001  =S  if event keypress is an S, check the modifier values
  461. **           19  check controlKey/optionKey/cmdKey
  462. **           00  all modifiers we are testing for should be false
  463. **           01  if above is true, keypress maps to item # 1
  464. ** =s190001  Same as =S, but lowercase
  465. ** =D190001  Same as =S, but maps to item #3
  466. ** =d190001  Same as =D, but lowercase
  467. ** =.190104  =.  if event keypress is a period, check the modifier values
  468. **           19  check controlKey/optionKey/cmdKey
  469. **           01  controlKey/optionKey should be false, cmdKey should be true
  470. **           04  if above is true, keypress maps to item # 4
  471. ** 1B190004  1B  if event keypress is an ESC, check the modifier values
  472. **           19  check controlKey/optionKey/cmdKey
  473. **           00  all modifiers we are testing for should be false
  474. **           04  if above is true, keypress maps to item # 4
  475. */
  476.  
  477. void            OffsetControl(ControlHandle ctl, short dx, short dy);
  478. /* This function is a convenient way to move a control a specified amount. */
  479.  
  480. void            DoDrawGrowIcon(WindowPtr window, Boolean horLine, Boolean verLine);
  481. /* This function draws the grow icon for the window in the specified manner.  You
  482. ** can clip out the horizontal or vertical line that is also drawn along with
  483. ** the grow icon, or you can have them draw. */
  484.  
  485. void            DoDrawControls(WindowPtr window, Boolean scrollBarsOnly);
  486. /* This function drawn all of the controls in a window, or just the scrollbar
  487. ** controls.  The reason for this function is that scrollbars are really
  488. ** tri-state, especially now with 7.0.  A scrollbar can be hilighted or not,
  489. ** or it can be drawn in a window that isn't the frontmost of the application
  490. ** plane.  DoDrawControls takes this third scrollbar state into consideration. */
  491.  
  492. void            DoDraw1Control(ControlHandle ctl, Boolean scrollBarsOnly);
  493. /* This function is where the work for scrollbar/control drawing is actually
  494. ** done.  DoDrawControls calls this function for each control in a window. */
  495.  
  496.  
  497.  
  498. /************** Window.c **************/
  499.  
  500. OSErr            DoNewWindow(FileRecHndl frHndl, WindowPtr *retWindow, WindowPtr behind, short attributes);
  501. /* This function is called by MacShell at appropriate times to give a document
  502. ** a window.  To create a document window, first a document is created via 
  503. ** AppNewDocument or AppOpenDocument.  If this succeeds then MacShell will give
  504. ** the document a window.  To do this, MacShell calls DoNewWindow.  DoNewWindow
  505. ** calls the content initialization procedure, which by default is InitContent.
  506. ** If you want a different content initialization procedure, replace the
  507. ** default procedure pointer initContentProc with our own.  Normally however,
  508. ** you will just place your own content initialization procedure in the
  509. ** function InitContent.  It is possible though that your
  510. ** application has more than one document type and window type.  If this
  511. ** is the case, then you may very well want an alternate content
  512. ** initialization procedure.  If you do, you will want to replace the
  513. ** default procedure pointer after the AppNewDocument or AppOpenDocument
  514. ** call and before the call to DoNewWindow.  (You may place the code for
  515. ** replacing the content initialization procedure and imaging procedure
  516. ** in the function AppInitDocument.  The defaults are already extablished
  517. ** at that point.  You would just replace them with the alternates. */
  518.  
  519. void            NewWindowTitle(WindowPtr window);
  520. /* Call this function if you want to change the title of the window. */
  521.  
  522. Boolean            GetWindowDirty(WindowPtr window);
  523. /* This function returns a boolean as to if the document for a window
  524. ** has been changed. */
  525.  
  526. void            SetWindowDirty(WindowPtr window);
  527. /* This function flags the document that owns the window as dirty. */
  528.  
  529. Boolean            DisposeAllWindows(void);
  530. Boolean            DisposeOneWindow(WindowPtr window, short saveMode);
  531. /* These functions do exactly as you would expect.  The saveMode indicates
  532. ** whether the window is being closed due to a close request, or due to the
  533. ** application being quit. */
  534.  
  535. WindowPtr        SetFilePort(FileRecHndl frHndl);
  536. /* This function sets the current port for the designated file.  It also returns
  537. ** the old port so that the port can be restored, if so desired. */
  538.  
  539. void            DoResizeWindow(WindowPtr window, short oldh, short oldv);
  540. /* This function is called when a window is resized.  This function needs to
  541. ** know the old size of the window.  The new size is determined by the
  542. ** dimensions of the window that was resized.  It moves and resizes the
  543. ** document scrollbars and growIcon (if any) to reflect the new size of
  544. ** the window.  It then calls the procedure stored in the procPtr field
  545. ** resizeContentProc, in case there is additional sizing necessary for the window.
  546. ** The default resizeContentProc is ResizeContent.  If you wish an alternate
  547. ** resizeContentProc, then you can replace the default in the function
  548. ** AppInitDocument, as the default is already established at this point. */
  549.  
  550. void            DoDrawFrame(WindowPtr window);
  551. /* This function may be called when an update event occurs for the window.
  552. ** If the update region intersects the frame region (calculated by DoCalcFrameRgn),
  553. ** then a frame update occurs and this function is called.  It redraws the
  554. ** document scrollbars and growIcon (if any) and then calls the procedure stored
  555. ** in the field drawFrameProc, which has a default value of DrawFrame.  If you wish
  556. ** an alternate drawFrameProc, then you can replace the default in the function
  557. ** AppInitDocument, as the default is already established at this point. */
  558.  
  559. RgnHandle        DoCalcFrameRgn(WindowPtr window);
  560. /* This function calculates the region that encompasses the document scrollbars
  561. ** and growIcon (if any).  The region is generated in global coordinates.  Since
  562. ** the frame region may encompass more than the MacShell-supported scrollbars and
  563. ** growIcon, a procedure is first called to see if there is anything additional
  564. ** in the frame region.  The field calcFrameRgnProc holds the procedure pointer
  565. ** that contributes any extra to the frame region.  This function is passed an
  566. ** empty region.  If there is no additional contribution to the frame region,
  567. ** then the region should be left empty.  Once this procedure is returned from,
  568. ** the remaining frame portion is added to this region.  The remaining portion
  569. ** would consist of MacShell document scrollbars and a growIcon, if there
  570. ** are any for this window.  The field calcFrameRgnProc is initialized to the
  571. ** default value CalcFrameRgn.  If you wish an alternate drawFrameProc, then you
  572. ** can replace the default in the function AppInitDocument, as the default is
  573. ** already established at this point. */
  574.  
  575. void            DoUpdateSeparate(WindowPtr window, RgnHandle *contRgn, RgnHandle *frameRgn);
  576. /* This function separates the update region into two portions.  One portion
  577. ** is the area that needs updating for the document scrollbars and growIcon
  578. ** (if any).  The other portion is the rest of the window content that needs
  579. ** updating.  This separation is so that the document scrollbars can be updated
  580. ** first, and then this area can be clipped out of the rest of the updating so
  581. ** that the window content doesn't draw over the document scrollbars and growIcon.
  582. ** The clipping is managed with just the visRgn.  This frees up the clipRgn for
  583. ** application specific clipping. */
  584.  
  585. void            BeginContent(WindowPtr window);
  586. /* This function clips out the document scrollbars and growIcon from the
  587. ** updatable area.  It also sets the origin of the port to the current
  588. ** document scrollbar values.  BeginContent must be balanced by a call
  589. ** to EndContent.  Calls to BeginContent and EndContent can not be
  590. ** nested.  BeginContent clips out the document scrollbar and growIcon area
  591. ** without involving the clipRgn so that the application is free to use the
  592. ** clipRgn as it sees fit.  The only caveat is that you can not modify the
  593. ** updateRgn between the BeginContent and EndContent calls, as anything
  594. ** contributed to the updateRgn between these calls will be lost.  If you
  595. ** need to do this, accumulate the areas in a separate region, call
  596. ** EndContent, and then call InvalRgn. */
  597.  
  598. void            EndContent(WindowPtr window);
  599. /* Calls to BeginContent must be balanced.  They also can't be nested.
  600. ** EndContent undoes the clipping of the document scrollbars and growIcon
  601. ** that BeginContent invoked. */
  602.  
  603. void            AdjustScrollBars(WindowPtr window);
  604. /* You call this function whenever you change the amount that the arrows scroll
  605. ** the document, or whenever the document changes size.  These values are first
  606. ** stored in the document's fileState structure.  Once the new values are in
  607. ** place, call AdjustScrollBars to affect all related changes. */
  608.  
  609. void            GetContentOrigin(WindowPtr window, Point *contOrg);
  610. /* This function returns the origin of the content of the window.  The value is
  611. ** gotten from the current value of the document scrollbars.  If a scrollbar
  612. ** is missing, that related value is assumed to be 0. */
  613.  
  614. void            SetContentOrigin(WindowPtr window, short newh, short newv);
  615. /* This function allows you to change the value of the document scrollbars,
  616. ** and by doing this, the document is scrolled to reflect the change, and
  617. ** an update event is generated for the document scroll. */
  618.  
  619. void            GetContentRect(WindowPtr window, Rect *contRct);
  620. /* This function returns a rectangle that represents the content area of the
  621. ** window less the scrollbar area. */
  622.  
  623. void            SetDocSize(FileRecHndl frHndl, short hSize, short vSize);
  624. /* This function sets the document size to the new designated size.  It also
  625. ** makes appropriate adjustments to the scrollbars to reflect the new size. */
  626.  
  627. void            DoImageDocument(FileRecHndl frHndl);
  628. /* This function is called whenever the content portion of a window needs to be
  629. ** updated or printed.  It simply calls the procedure pointer stored in the field
  630. ** imageProc.  The field imageProc is initialized to ImageDocument.  If you wish
  631. ** an alternate imageProc, then you can replace the default in the function
  632. ** AppInitDocument, as the default is already established at this point. */
  633.  
  634. void            DoContentClick(WindowPtr window, EventRecord *event);
  635. /* This function is called whenever the content portion of a window is clicked in.
  636. ** It simply calls the procedure pointer stored in the field contentClickProc.
  637. ** The field contentClickProc is initialized to ContentClick.  If you wish
  638. ** an alternate contentClickProc, then you can replace the default in the function
  639. ** AppInitDocument, as the default is already established at this point. */
  640.  
  641. void            DoContentKey(WindowPtr window, EventRecord *event);
  642. /* This function is called whenever a key event occurs that needs to be handled
  643. ** by the window.  It simply calls the procedure pointer stored in the field
  644. ** contentKeyProc.  The field contentClickProc is initialized to ContentClick.  If
  645. ** you wish an alternate contentKeyProc, then you can replace the default in the function
  646. ** AppInitDocument, as the default is already established at this point. */
  647.  
  648.  
  649.  
  650. /************** Window2.c **************/
  651.  
  652. OSErr            InitContent(FileRecHndl frHndl, WindowPtr window);
  653. /* This function is the default function for initializing the content area
  654. ** of a window.  It is called by DoNewWindow unless you change the default
  655. ** content initialization procedure pointer. */
  656.  
  657. void            ImageDocument(FileRecHndl frHndl);
  658. /* This function is the default function for imaging the document into the
  659. ** window or into the printer port.  It is called in response to update
  660. ** events, or in response to the user printing.  You can change the imaging
  661. ** procedure pointer if you wish.  This is only called as a default. */
  662.  
  663. void            ResizeContent(WindowPtr window, short oldh, short oldv);
  664. /* This function is the default function for resizing the document content.
  665. ** MacShell calls ResizeWindow, which handles resizing the document scrollbars.
  666. ** It then calls the content resizing procedure.  This function is called by
  667. ** ResizeWindow unless you change the default content resizing
  668. ** procedure pointer. */
  669.  
  670. void            DrawFrame(FileRecHndl frHndl, WindowPtr window);
  671. /* This function is the default function for drawing the remainder of the
  672. ** frame.  The MacShell document scrollbars and growIcon, if any, are already
  673. ** drawn.  This function is called by DoDrawFrame unless you change the
  674. ** default frame drawing procedure pointer. */
  675.  
  676. void            CalcFrameRgn(FileRecHndl frHndl, WindowPtr window, RgnHandle rgn);
  677. /* This function is the default function for contributing to the frame calculation.
  678. ** MacShell document scrollbars and growIcon are contributed later automatically.
  679. ** Only if you have additional (or alternate) frame parts in your window should
  680. ** you add any code to this function.  CalcFrameRgn is called by DoCalcFrameRgn
  681. ** unless you change the default frame region calculation procedure pointer.
  682. ** If you have no additional frame contribution, then you should simply return
  683. ** the region passed in unchanged. */
  684.  
  685. void            ContentClick(WindowPtr window, EventRecord *event);
  686. /* This function is the default function for handling click events for the window. */
  687.  
  688. void            ContentKey(WindowPtr window, EventRecord *event);
  689. /* This function is the default function for handling key events for the window. */
  690.  
  691.